#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
//判断是否构成三角形
bool triangle(int a, int b, int c) {
	return a + b > c && a + c > b && c + b > a;
}

//找周长最长
int max_c(vector<int>& len, int n) {
	int a, b, c;
	int i = 0;
	sort(len.begin(), len.end(), greater<int>());

	while (true) {
		a = len[i], b = len[i + 1], c = len[i + 2];
		if (!triangle(a, b, c)) {
			i++;
		}
		else {
			return a + b + c;
		}
	}
	return 0;
}
double triangleArea(int a, int b, int c) {
	if (!triangle(a, b, c)) return 0.0;
	double s = (a + b + c) / 2.0;
	return sqrt(s * (s - a) * (s - b) * (s - c));
}
//找面积最大
double max_s(vector<int>& len, int m) {
	double maxArea = 0.0;
	sort(len.begin(), len.end(), greater<int>());
	for (int i = 0; i < m - 2; ++i) {
		for (int j = i + 1; j < m - 1; ++j) {
			for (int k = j + 1; k < m; ++k) {
				double area = triangleArea(len[i], len[j], len[k]);
				if (area > maxArea) {
					maxArea = area;
				}
			}
		}
	}
	return maxArea;
}
int main() {
	int m;
	cout << "请输入木棍的数目m=" << " ";
	cin >> m;
	vector<int> len(m);
	cout << "输入" << m << "根木棍的长度" << endl;

	for (int i = 0; i < m; i++) {
		cin >> len[i];
	}
	int maxc = max_c(len, m);
	double maxs = max_s(len, m);

	if (maxc == 0 && maxs == 0) {
		cout << "0" << endl;
	}
	else {
		cout << "构成的最大三角形周长为：" << maxc << endl;
		cout << "构成的最大三角形面积为：" << maxs << endl;
	}
	return 0;

}
